package com.xingtu.testSerialport.entity

import com.blankj.utilcode.util.LogUtils
import com.xingtu.testSerialport.utils.SerialPortUtils
import java.io.Serializable

class BoardCardS6 : Serializable {
    /**
     * 横滚角
     */
    var rollAngle: String? = null

    /**
     * 俯仰角
     */
    var pitchAngle: String? = null

    /**
     *  航向角
     */
    var courseAngle: String? = null

    /**
     *  //RTK定位（0未定位、1单点定位、2、码差分、4固定解、5浮点解），整型1字节；
     */
    var RTKStatus = 0

    /**
     * 卫星数量
     */
    var satellites = 0

    /**
     * 差分延迟
     */
    var differentialDelay = 0

    /**
     * 状态码
     */
    var code = 0

    /**
     *  状态位
     */
    var statusBit: String? = null


    //<editor-fold desc="设置信息">
    fun setData(s6Hex2: String) {
        if (s6Hex2.startsWith("FFA44A", true) && s6Hex2.length > 10) {
            val index = s6Hex2.substring(6, 8)

            val size = SerialPortUtils.getHexB10Int(index) * 2
            LogUtils.e("index=${index}  size=${size}   s6Hex2.size=${s6Hex2.length}")
            if (s6Hex2.length >= size) {

                val b = s6Hex2.substring(0, size.toInt())
                code = SerialPortUtils.getHexB10Int(b.substring(8, 10)).toInt()
                val b1 = b.substring(10, size.toInt())
                LogUtils.e("解析的=${b} code=${b.substring(8, 10)} 功能码code=${code}  b1=${b1}")
                when (code) {
                    SerialPortUtils.rCode1 -> {
                        LogUtils.e("接收 code1")
                        val data1 = b1.substring(0, 8)
                        val data2 = b1.substring(8, 16)
                        val data3 = b1.substring(16, 24)
                        val data4 = b1.substring(24, 26) //RTK定位状态
                        val data5 = b1.substring(26, 28) //卫星数
                        val data6 = b1.substring(28, 30) //差分延迟
                        rollAngle = SerialPortUtils.getAngleStr(data1, true)
                        pitchAngle = SerialPortUtils.getAngleStr(data2, true)
                        courseAngle = SerialPortUtils.getAngleStr(data3, true)

                        RTKStatus = SerialPortUtils.getHexB10Int(data4).toInt()
                        satellites = SerialPortUtils.getHexB10Int(data5).toInt()
                        differentialDelay = SerialPortUtils.getHexB10Int(data6).toInt()
                        //翻滚角-3.8766   俯仰角  12.3122   航向角313.2667  RTK定位状态4  卫星颗数21
                        LogUtils.e(
                            s6Hex2,
                            "横滚角=${data1} 重新排序=${SerialPortUtils.sortNewHex2(data1)}  转换=${rollAngle}",
                            "俯仰角=${data2} 重新排序=${SerialPortUtils.sortNewHex2(data2)}  转换=${pitchAngle}",
                            "航向角=${data3} 重新排序=${SerialPortUtils.sortNewHex2(data3)}  转换=${courseAngle}",
                            "RTK=${data4}  转换=${RTKStatus}",
                            "卫星数=${data5}  转换=${satellites}",
                            "差分延迟=${data5}  转换=${differentialDelay}"
                        )
                    }
                    SerialPortUtils.rCode2 -> {

                    }
                    SerialPortUtils.rCode3 -> {

                    }
                }

            }
        }
    }
    //</editor-fold>
}